package kgame5.kgui.gameui {
import kgame5.kgui.GP;

import flash.display.MovieClip;
import flash.events.Event;
import flash.utils.getTimer;

/**
 * @author kk
 * 一个圆环，表示某东西的进度，直接使用原因是因为有坦克头上要有加载进度条
 */
public class LoadingRing {
	
	private var mc:MovieClip;//要画上去的容器
	public var R:int=6;//圈的半径
	
	private var color:int=0xff0000;//是红色是为了要醒目
	
	private var DurMS:int;//进度条持续时间
	private var startTime:int;
	
	public function LoadingRing(p_mc:MovieClip){
		mc=p_mc;
	}
	public function setColor(c:int):void{
		color=c;
	}
	
	public function start(durMS:int):void{
		mc.visible=true;//鼠标屏蔽
		DurMS=durMS;
		startTime=getTimer();
		mc.addEventListener(Event.ENTER_FRAME, efh);
	}
	private function efh(e:Event):void{
		var curTime:int=getTimer();
		var p:int=(curTime-startTime)*100/DurMS;
		//T.p("updaet",curMS,startMS,p);
		setProgress(p);
	}
	private function setProgress(p:Number=100):void{
		//T.p("setProgress",p);
		var arc:Number=360*p/100;//弧度
		
		if(p<100){
			GP.clear(mc.graphics);
			GP.drawArc2(mc.graphics,3, color, undefined, 0, 0, 0, arc, R, R);
		}
//		else if(p==100){
//			GP.clear(mc.graphics);
//		}
	}
	public function clear():void{
		mc.visible=false;//鼠标屏蔽
		GP.clear(mc.graphics);
		mc.removeEventListener(Event.ENTER_FRAME, efh);
	}
}//end of class
}

